/**
 * Copyright 2013 ABSir's Studio
 * 
 * All right reserved
 *
 * Create on 2013-6-17 上午10:03:38
 */
package com.absir.bean.core;

import java.lang.annotation.Annotation;

import com.absir.bean.basis.BeanDefine;
import com.absir.bean.basis.BeanFactory;
import com.absir.bean.basis.BeanName;
import com.absir.core.kernel.KernelObject;

/**
 * @author absir
 * 
 */
public abstract class BeanDefineAbstract implements BeanDefine {

	/** beanName */
	String beanName;

	/**
	 * @param annotations
	 * @return
	 */
	protected static String[] getBeanParamNames(Annotation[][] annotations) {
		int length = annotations.length;
		String[] paramNames = new String[annotations.length];
		for (int i = 0; i < length; i++) {
			paramNames[i] = null;
			for (Annotation annotation : annotations[i]) {
				if (annotation instanceof BeanName) {
					paramNames[i] = ((BeanName) annotation).value();
					break;
				}
			}
		}

		return paramNames;
	}

	/**
	 * @param beanName
	 */
	public void setBeanName(String beanName) {
		this.beanName = beanName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.absir.bean.basis.BeanDefine#getBeanFactory()
	 */
	@Override
	public BeanFactory getBeanFactory() {
		return BeanFactoryImpl.getInstance();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return KernelObject.hashCode(getBeanComponent());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj == null || !(obj instanceof BeanDefine)) {
			return false;
		}

		if (getBeanComponent() == null) {
			return ((BeanDefine) obj).getBeanComponent() == null;

		} else {
			return KernelObject.equals(getBeanComponent(), ((BeanDefine) obj).getBeanComponent());
		}
	}
}
